
const month = [
  "Jan", "Feb", "Mar", "Apr",
  "May", "June", "July", "Aug",
  "Sep", "Oct", "Nov", "Dec"];

let d = new Date();

function date() {
  //var d = new Date() ;
  document.getElementById("t").innerHTML = d.getDate() + " / " + month[d.getMonth()] + " / " + d.getFullYear();
  loadStorage('msg');
}

function home_page() {
  window.history.back(-1);
}

function saveStorage(id) {
  //获取textarea的value值
  var data = document.getElementById(id).value;
  if (data == "")
    return;
  //获取当前时间戳
  var time = new Date().getTime();
  //将时间戳作为键值，textarea的value值作为键值的内容保存在本地数据库
  //根据对应板块的不同，更改对应的键值，实现不同内容分别呈现（暂时不知道怎么实现，为弄清localStorage的存储是依据什么顺序）
  localStorage.setItem(time, data);
  //保存成功后提示成功
  console.log("数据已保存");
  //设置loadStorage函数的传参（ID值）
  loadStorage('msg');
  document.getElementById(id).value = "";
}

function loadStorage(id) {
  var result = '<p>';
  //遍历本地数据所有内容
  for (var i = 0; i < localStorage.length; i++) {
    //获取每一条新增的键值
    var kes = localStorage.key(i);
    //console.log(kes) ;
    //获取新增键值的内容
    var value = localStorage.getItem(kes);
    //获取时间对象
    var date = new Date();
    date.setTime(kes);
    var time = date.getHours() + ":" + date.getMinutes() + "   " + month[date.getMonth()] + "/" + date.getDate();

    //将所有新增内容添加到result变量中
    result += "“" + value + "”" + '</br>' + time + '</br>' + '</br>'
  }
  result += '</p>';
  var target = document.getElementById(id);
  //将所有内容添加到元素中显示
  target.innerHTML = result;

}

function clearStorage() {
  localStorage.clear();
  document.getElementById('msg').value = "";
  loadStorage('msg');
  console.log("清除完毕");
}

function clearText(id) {
  document.getElementById(id).value = "";
}

function _alert() {
  alert("博主暂未开放该相册~") ;
}
